<template>
  <Header :type="'long'">
    <p class="switchs">
      商家配送&nbsp;
      <el-switch v-model="send" @change="switchTag"> </el-switch>
    </p>
  </Header>
</template>
<script>
import {
  OFFORONDISTRIBUTIONCONFIG,
  SHOWDISTRIBUTIONCONFIG
} from "../../service";

export default {
  data() {
    return {
      send: false
    };
  },
  created() {
    this.lock();
  },
  methods: {
    showTag(e) {
      this.shows = e;
    },
    async switchTag() {
      await OFFORONDISTRIBUTIONCONFIG({ type: 1, val: this.send }).then(res => {
        let { code, msg } = res;
        if (code === 200) this.send = true;
        this.$message({
          message: msg,
          type: code === 200 ? "success" : "error"
        });
      });
    },
    async lock() {
      await SHOWDISTRIBUTIONCONFIG({ type: 1 }).then(res => {
        let { code, data } = res;
        if (code === 200) this.send = JSON.parse(data.config_value);
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.switchs {
  font-size: 20px;
  font-weight: bold;
  padding-left: 20px;
}
</style>
